<?php

class Listener_Order_Canceled_Qywx extends Listener_Base
{
    public function handle($args)
    {
        $self       = new self();
        $self->args = $args;
        //判断队列是否开启,如果开启则把任务推送到队列
        if ($self->queue_status) {
            Queue::in('default', Listener_Order_Canceled_Qywx::class, $args);
        } else {
            $self->perform();
        }
    }

    /**
     * @return void
     */
    public function perform()
    {
        $args    = $this->args;
        $ordersn = $args['ordersn'];

        $order = DB::select()
            ->from('member_order')
            ->where('ordersn', '=', $ordersn)
            ->execute()
            ->current();
        if ($order) {
            $result = St_QywxService::send_product_order_qywx(St_NoticeCommon::PRODUCT_ORDER_CANCEL_MSGTAG, $order);
            St_Log::write('企业微信', array( 'ordersn' => $ordersn, 'result'=> $result), 'event/order_canceled/log');
        }
    }

}